home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CHyperCuberApp.cp < prev    next >
Text File  |  1994-05-02  |  10KB  |  352 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CHyperCuberApp.h
  3. //|
  4. //| This file contains the implementation of the HyperCuber Application class.
  5. //|___________________________________________________________________________
  6.  
  7. #include "CAboutDialogDirector.h"
  8. #include "CKeyControlsDirector.h"
  9. #include "CMouseControlsDirector.h"
  10. #include "CNCubeDialogDirector.h"
  11. #include "CHyperCuberApp.h"
  12. #include "CHyperCuberDoc.h"
  13. #include "CHyperCuberPane.h"
  14. #include "CHyperCuberPrefs.h"
  15. #include "CPrefsDialogDirector.h"
  16. #include "HyperCuber Commands.h"
  17. #include "HyperCuber Errors.h"
  18.  
  19. #include <CFWDesktop.h>
  20.  
  21.  
  22. //============================ Constants ============================\\
  23.  
  24. #define        kExtraMasters        12
  25. #define        kRainyDayFund        20480
  26. #define        kCriticalBalance    20480
  27. #define        kToolboxBalance        20480
  28.  
  29.  
  30. //============================ Globals ============================\\
  31.  
  32. extern    OSType        gSignature;
  33. extern    CBartender    *gBartender;
  34. extern    CDesktop    *gDesktop;
  35.  
  36. CHyperCuberPrefs    *gPrefs;
  37.  
  38. extern CGrafPtr        left_offscreen_cptr;
  39. extern CGrafPtr        right_offscreen_cptr;
  40. extern CGrafPtr        offscreen_cptr;
  41.  
  42. extern Boolean        menubar_hidden;
  43.  
  44.  
  45. //============================ Prototypes ============================\\
  46.  
  47. extern void terminal_error(short error);
  48. extern void create_offscreen_pixmap(CGrafPort *color_port, Rect *bounds);
  49. extern void dispose_offscreen_pixmap(CGrafPort *color_port);
  50. extern "C" void init_menubar(void);
  51. extern "C" void show_menubar(void);
  52.  
  53.  
  54. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. //| CHyperCuberApp::IHyperCuberApp
  56. //|
  57. //| Purpose: Initialize the application
  58. //|
  59. //| Parameters: none
  60. //|____________________________________________________________
  61.  
  62. void CHyperCuberApp::IHyperCuberApp(void)
  63. {
  64.  
  65.     CApplication::IApplication( kExtraMasters, kRainyDayFund, 
  66.                         kCriticalBalance, kToolboxBalance);
  67.     
  68.     gPrefs = new(CHyperCuberPrefs);                    //  Create the preferences
  69.     gPrefs->IHyperCuberPrefs();                        //  Initialize prefs to default
  70.     gPrefs->Load();                                    //  Load the preferences in from the file
  71.  
  72.     Rect offscreen_bitmap_bounds = {0, 0, 1, 1};    //  Create the empty offscreen bitmaps
  73.     create_offscreen_pixmap(left_offscreen_cptr,         
  74.                             &offscreen_bitmap_bounds);
  75.     create_offscreen_pixmap(right_offscreen_cptr,         
  76.                             &offscreen_bitmap_bounds);
  77.  
  78.     init_menubar();                                    //  Prepare to possibly hide the menubar
  79.  
  80. }    //==== CHyperCuberApp::IHyperCuberApp() ====\\
  81.  
  82.  
  83.  
  84. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. //| CHyperCuberApp::MakeDesktop
  86. //|
  87. //| Purpose: Create the desktop (which supports floating windows)
  88. //|
  89. //| Parameters: none
  90. //|______________________________________________________________
  91.  
  92. void CHyperCuberApp::MakeDesktop(void)
  93. {
  94.  
  95.     gDesktop = new(CFWDesktop);                        //  Create and initialize the desktop
  96.     ((CFWDesktop *) gDesktop)->IFWDesktop(this);
  97.  
  98. }    //==== CHyperCuberApp::MakeDesktop() ====\\
  99.  
  100.  
  101.  
  102. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. //| CHyperCuberApp::InspectSystem
  104. //|
  105. //| Purpose: Gather information about the current OS
  106. //|
  107. //| Parameters: none
  108. //|__________________________________________________
  109.  
  110. void CHyperCuberApp::InspectSystem( void)
  111. {
  112.  
  113.     OSErr        err;
  114.     SysEnvRec    environs;
  115.     long        response;
  116.     
  117.     CApplication::InspectSystem();                        //  Do superclass's inspection
  118.     
  119.     if (!gSystem.hasFPU)                                //  We must have a Floating Point Unit
  120.         terminal_error(missing_fpu);
  121.     
  122.     if (!gSystem.hasGestalt)                            //  We must have the gestalt manager
  123.         terminal_error(missing_gestalt);
  124.  
  125.     if (!gSystem.hasColorQD)                            //  We must have Color QuickDraw
  126.         terminal_error(missing_color_qd);
  127.  
  128.     if (Gestalt(gestaltFindFolderAttr, &response) != noErr)    //  We must have FindFolder
  129.         terminal_error(missing_folder_manager);
  130.  
  131.     Gestalt(gestaltProcessorType, &response);            //  We must have a 68020
  132.     if (response < gestalt68020)
  133.         terminal_error(missing_68020);    
  134.     
  135. }    //==== CHyperCuberApp::InspectSystem() ====\\
  136.  
  137.  
  138.  
  139. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. //| CHyperCuberApp::SetUpFileParameters
  141. //|
  142. //| Purpose: Specify the kinds of files we open
  143. //|
  144. //| Parameters: none
  145. //|_________________________________________________________
  146.  
  147. void CHyperCuberApp::SetUpFileParameters(void)
  148.  
  149. {
  150.     inherited::SetUpFileParameters();        //  Call superclass
  151.  
  152.     sfNumTypes = 1;                            //  We know only of 'TEXT' files
  153.     sfFileTypes[0] = 'TEXT';
  154.  
  155.     gSignature = 'HCub';                    //  Initialize our signature
  156.  
  157. }    //==== CHyperCuberApp::SetUpFileParameters() ====\\
  158.  
  159.  
  160.  
  161. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162. //| CHyperCuberApp::DoCommand
  163. //|
  164. //| Purpose: Handle application commands
  165. //|
  166. //| Parameters: theCommand: the command to handle
  167. //|_________________________________________________________
  168.  
  169. void CHyperCuberApp::DoCommand(long theCommand)
  170. {
  171.  
  172.     switch (theCommand)
  173.         {
  174.     
  175.         case cmdAbout:                                    //  Put up the "About HyperCuber..." dialog
  176.         
  177.             CAboutDialogDirector                        //  Create the director
  178.                     *about_dialog_director =
  179.                             new (CAboutDialogDirector);
  180.             about_dialog_director->IAboutDialogDirector(this);
  181.             about_dialog_director->TalkToUser();        //  Get input
  182.             about_dialog_director->Dispose();
  183.             
  184.             break;
  185.  
  186.         case cmdColors:                                    //  Put up the Colors... dialog
  187.         
  188.             CPrefsDialogDirector *dialog_director = new (CPrefsDialogDirector);
  189.             dialog_director->IPrefsDialogDirector(this);
  190.             dialog_director->TalkToUser();
  191.             dialog_director->Dispose();
  192.             ((CHyperCuberPane *) itsDocument->itsMainPane)->Refresh();
  193.             
  194.             gPrefs->Update();                            //  Save the preferences to the prefs file
  195.             gPrefs->Save();
  196.  
  197.             break;
  198.  
  199.         case cmdKeyControls:                            //  Put up the Key Controls... dialog
  200.         
  201.             CKeyControlsDirector *kcdialog_director = new (CKeyControlsDirector);
  202.             kcdialog_director->IKeyControlsDirector(this);
  203.             kcdialog_director->TalkToUser();
  204.             kcdialog_director->Dispose();
  205.             
  206.             gPrefs->Update();                            //  Save the preferences to the prefs file
  207.             gPrefs->Save();
  208.  
  209.             break;
  210.  
  211.         case cmdMouseControls:                            //  Put up the Mouse Controls... dialog
  212.         
  213.             CMouseControlsDirector *mcdialog_director = new (CMouseControlsDirector);
  214.             mcdialog_director->IMouseControlsDirector(this);
  215.             mcdialog_director->TalkToUser();
  216.             mcdialog_director->Dispose();
  217.             
  218.             gPrefs->Update();                            //  Save the preferences to the prefs file
  219.             gPrefs->Save();
  220.             
  221.             break;
  222.  
  223.         case cmdNewNCube:                                    //  Create a new n-dimensional cube
  224.             
  225.             CNCubeDialogDirector *ncdialog_director = new (CNCubeDialogDirector);
  226.             ncdialog_director->INCubeDialogDirector(this);        //  Create and display dialog
  227.             long dimension = ncdialog_director->TalkToUser();    //  Get dimension of n-cube to create
  228.             ncdialog_director->Dispose();
  229.  
  230.             if (dimension)
  231.                 {
  232.                 itsDocument = new(CHyperCuberDoc);            //  Create the n-cube document
  233.                 itsDocument->IHyperCuberDoc(this, TRUE);
  234.                 itsDocument->NewNCube(dimension);
  235.                 }
  236.                 
  237.             break;
  238.  
  239.         default:    inherited::DoCommand(theCommand);    //  Handle normal commands
  240.                     break;
  241.         }
  242.  
  243. }    //==== CHyperCuberApp::DoCommand() ====\\
  244.  
  245.  
  246.  
  247. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248. //| CHyperCuberApp::UpdateMenus
  249. //|
  250. //| Purpose: Enable the application's menus.
  251. //|
  252. //| Parameters: none
  253. //|___________________________________________________________________________
  254.  
  255. void CHyperCuberApp::UpdateMenus()
  256. {
  257.  
  258.     inherited::UpdateMenus();                     // Enable standard commands */
  259.  
  260.     gBartender->EnableCmd(cmdOpen);                //  Enable the Open... menu item  
  261.     gBartender->EnableCmd(cmdColors);            //  Enable Colors... menu item  
  262.     gBartender->EnableCmd(cmdKeyControls);        //  Enable Key Controls... menu item  
  263.     gBartender->EnableCmd(cmdMouseControls);    //  Enable Mouse Controls... menu item  
  264.     gBartender->EnableCmd(cmdNewNCube);            //  Enable New NCube menu item  
  265.  
  266. }    //==== CHyperCuberApp::UpdateMenus() ====\\
  267.  
  268.  
  269.  
  270. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271. //| CHyperCuberApp::Exit
  272. //|
  273. //| Purpose: clean up before quitting.  This saves the preferences.
  274. //|
  275. //| Parameters: none
  276. //|___________________________________________________________________________
  277.  
  278. void CHyperCuberApp::Exit()
  279. {
  280.  
  281.     show_menubar();                                //  Show the menu bar, if it's hidden
  282.  
  283.     gPrefs->Save();                                //  Save the preferences to the preferences file
  284.  
  285.     dispose_offscreen_pixmap(left_offscreen_cptr);    //  Get rid of the offscreen pixmaps
  286.     dispose_offscreen_pixmap(right_offscreen_cptr);
  287.     
  288. }    //==== CHyperCuberApp::Exit() ====\\
  289.  
  290.  
  291.  
  292. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  293. //| CHyperCuberApp::CreateDocument
  294. //|
  295. //| Purpose: Create a new CHyperCuberDoc.
  296. //|
  297. //| Parameters: none
  298. //|___________________________________________________________________________
  299.  
  300. void CHyperCuberApp::CreateDocument()
  301.  
  302. {
  303.     
  304.     TRY
  305.         {
  306.         itsDocument = new(CHyperCuberDoc);            //  Create the document
  307.         itsDocument->IHyperCuberDoc(this, TRUE);
  308.         itsDocument->NewFile();
  309.  
  310.         AddDirector(itsDocument);                    //  Add this document to the director list
  311.         }
  312.     
  313.     CATCH
  314.         {
  315.         if (itsDocument) itsDocument->Dispose();    //  If we failed, throw away the document
  316.         }
  317.     ENDTRY;
  318.  
  319. }    //==== CHyperCuberApp::CreateDocument() ====\\
  320.  
  321.  
  322.  
  323. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  324. //| CHyperCuberApp::OpenDocument
  325. //|
  326. //| Purpose: Open a graphics file
  327. //|
  328. //| Parameters: macSFReply: the file to open
  329. //|___________________________________________________________________________
  330.  
  331. void CHyperCuberApp::OpenDocument(SFReply *macSFReply)
  332. {
  333.  
  334.     CHyperCuberDoc    *theDocument = NULL;
  335.     
  336.     TRY
  337.         {
  338.         theDocument = new(CHyperCuberDoc);            //  Create a new document
  339.         theDocument->IHyperCuberDoc(this, TRUE);
  340.         theDocument->OpenFile(macSFReply);            //  Open the file
  341.         
  342.         AddDirector(theDocument);                    //  Add this document to the director list
  343.         }
  344.     
  345.     CATCH
  346.         {
  347.          if (theDocument) theDocument->Dispose();    //  If this failed, throw away the document
  348.         }
  349.         
  350.     ENDTRY;
  351.     
  352. }    //==== CHyperCuberApp::OpenDocument() ====\\